<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/icons.css" />
	<style>
		.table tr:first-child {
			background: url(static/img/tableheader-bg.gif) no-repeat left top;
			background-color: #DCE9F2;
			border-top: 1px solid #CBD6DE;
			border-bottom: 1px solid #ADBECB;
			color: #467aa7;
			font-size: 13px;
			font-weight: bold;
		}

		.table {
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			font-size: 13px;
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			overflow: auto;
			max-height: 400px;
		}

		.table td {
			height: 40px;
			text-align: center;
			border: 1px solid #CBD6DE;
			padding: 0;
			margin: 0;
		}
	</style>
</head>

<body>
	<div class="aui-content">
		<div class="aui-content aui-content-padded" style="text-align:center;width: 72%;float:left;">
			<input type="text" placeholder="请输入物料编号/物料名称搜索" id="searchValue" />
		</div>
		<div class="aui-content aui-content-padded" style="text-align:center;width: 5%;float:left;">
			<p>
				<button type="button" class="aui-btn aui-btn-info aui-iconfont" style="font-size: 20px;"
					onclick="doSearch();">查询</button>
			</p>
		</div>
	</div>

	<div id="wrap">

		<div class="table" style="background-color:white;">
			<table id='chkYqTable' class="table" style='width:100%;'>
				<thead id="chkYqTableHead">
				</thead>
				<tbody id="chkYqTableBody">
				</tbody>
			</table>
		</div>
		<br />
	</div>

	<div class="aui-content">
		<div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
			<p>
			<div class="aui-btn aui-btn-info" onclick="doSaveYq()" style="width: 100%;height: 100%;">
				<span class="aui-iconfont" style="font-size: 26px;">确定</span>
			</div>
			</p>
		</div>

	</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>

	var YqStrs = "";
	// 传入后台的参数，用来做模糊查询使用的
	var condition = "";
	var mrlYqCodes = "";
	var myobj = [];
	var list = [];
	apiready = function () {
		mrlYqCodes = api.pageParam.mrlYqCodes;
		getUnExistCHKModelTaskYq(mrlYqCodes, condition);
	}

	/**查询框*/
	function doSearch() {
		condition = document.getElementById('searchValue').value;
		getUnExistCHKModelTaskYq(mrlYqCodes, condition);
	}

	function getUnExistCHKModelTaskYq(mrlYqCodes, condition) {
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getUnExistCHKModelTaskYQ";
		var un = localStorage.getItem('un');
		// var pw = localStorage.getItem('pw');
		// var serverIp = localStorage.getItem('serverIp');
		// var serverPort = localStorage.getItem('serverPort');
		// var serverProject = localStorage.getItem('serverProject');
		// var url1 = serverIp+":"+serverPort+"/"+serverProject;

		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;

		var data = {
			values: {
				un: un,
				// pw: pw,
				// url: url1,
				existCodes: mrlYqCodes,
				condition: condition
			}
		};

		// ajaxForData(params,data,false,function(ret, err){
		// 	myobj = eval("("+ret.data+")");
		// 	$("#chkYqTable").children().remove();
		// 	$("#chkYqTable").append("<tr id='tr2'><td width='10%' algin='center'></td><td style='display:none' algin='center'>物料主键</td><td width='10%' algin='center'>物料编号</td><td width='80%' algin='center'>物料名称</td></tr>");
		//     for (var i = 0; i < myobj.length; i++) {

		// 		var YqId = myobj[i].YqId;
		// 		var mrlYqGid = myobj[i].mrlYqGid;
		// 		var mrlYqCode = myobj[i].mrlYqCode;
		// 		var mrlYqName = myobj[i].mrlYqName;			
		// 		var remarkYq = myobj[i].remarkYq;				
		// 		var str = "<tr ><td width='10%' algin='center'><input id='"+YqId+"' type='checkbox' onclick='setEquipMCHKModelYq("+i+");'></td><td width='10%' algin='center'>"+mrlYqCode+"</td><td width='80%' algin='center'>"+mrlYqName+"</td></tr>"
		// 		$("#chkYqTable").append(str);				
		// 	}
		// });

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//成功
				if (myobj.code == '0') {

					list = myobj.list;
					var html = "";
					// alert(list)
					// $("#chkYqTable").children().remove();
					// $("#chkYqTableHead").append("<tr id='tr2'><td width='10%' algin='center'></td><td style='display:none' algin='center'>物料主键</td><td width='10%' algin='center'>物料编号</td><td width='80%' algin='center'>物料名称</td></tr>");
					html += "<tr id='tr2'><td width='10%' algin='center'></td><td style='display:none' algin='center'>物料主键</td><td width='10%' algin='center'>物料编号</td><td width='80%' algin='center'>物料名称</td></tr>";
					$api.html($api.byId("chkYqTableHead"), html);
					var str = "";
					if (list != undefined) {
						for (var i = 0; i < list.length; i++) {

							var YqId = list[i].YqId;
							var mrlYqGid = list[i].mrlYqGid;
							var mrlYqCode = list[i].mrlYqCode;
							var mrlYqName = list[i].mrlYqName;
							var remarkYq = list[i].remarkYq;
							str = "<tr ><td width='10%' algin='center'><input id='" + YqId + "' type='checkbox' onclick='setEquipMCHKModelYq(" + i + ");'></td><td width='10%' algin='center'>" + mrlYqCode + "</td><td width='80%' algin='center'>" + mrlYqName + "</td></tr>"
							$("#chkYqTableHead").append(str);
							//chkYqTableBody	
							// $api.html($api.byId("chkYqTableBody"), str);
						}
					} else {
						//$api.html($api.byId("chkYqTableBody"), "");
						$("#chkYqTableHead").append("");
					}
				} else if (myobj.code == '1') {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	function setEquipMCHKModelYq(i) {
		var obj = list[i];
		if ($('#' + obj.YqId).is(':checked')) {
			var id = obj.YqId.replace("\n", "");
			var mrlYqGid = obj.mrlYqGid.replace("\n", "");
			var code = obj.mrlYqCode.replace("\n", "");
			var name = obj.mrlYqName.replace("\n", "");
			var remark = obj.remarkYq.replace("\n", "");

			var str = id + ":" + mrlYqGid + ":" + code + ":" + name + ":" + remark;
			//判断选则的点检项是否已经选择，如果已选则删除，如果未选则添加
			if (YqStrs == "") {
				YqStrs = str;
			} else {
				YqStrs = YqStrs + "," + str;
			}
		} else {
			YqStrs = "";
		}
	}

	function doSaveYq() {
		api.closeWin();

		api.execScript({
			// name : 'about2',
			// frameName : 'about-con',
			name: 'uemChkTask',
			script: 'setAddYq("' + YqStrs + '")'
		});
	}

</script>

</html>